function main(defaultParams) {
    debugger;
    const self = this;
    const formPartEle = self.$$element("form_part_80r0ke");
    const formEle = formPartEle.$$getRenderElement();
    const pageRenderElement = this.$$root().$parent.$parent.$parent;

    const formValue = formEle.$$getFormValue()['ds_tbl:t_355f38575f894287a8e40d8af41ae10c'];
    const unitTypeCode = formValue.checkbox_715py5 || []; // 多选机构类型

    const dataForSave = buildUnitInfo(formEle, formValue, unitTypeCode);
    console.log("构建后的数据：", dataForSave);

    saveForm(dataForSave).then(() => {
        pageRenderElement.goHistory(-1); // 保存成功后返回
    });
}

function saveForm(data) {
    return api.DATA_SOURCE_EXECUTE(
        "ds_api:8222f7d2-792a-408d-9b80-2e6ed3160030",
        "api",
        [],
        [],
        JSON.stringify(data)
    );
}

function buildUnitInfo(formEle, formValue, unitTypeCode) {
    const id = formValue && formValue.id; // 有 id 为编辑，没有则为新增

    const unitBaseInfo = {
        id,
        unitName: formValue.text_input_6pb5tu,
        unitNameAbbr: formValue.text_input_b2uvyd,
        seniorId: formValue.tree_single_select_13q1ge,
        unitPropertyCode: formValue.single_select_gl6qfp,
        regionId: formValue.tree_single_select_1sohfs,
        usercenterUnitId: formValue.single_select_gl6qfp,
        syncUsercenterFlag: formValue.radio_61g5vf,
        unitTypeCode: (unitTypeCode || []).join(","),
        socialCreditCode: formValue.text_input_5uxl5t,
        unitLayerLevelCode: formValue.single_select_aitj6e,
        legalDelegateMan: formValue.text_input_go3c3p,
        foundDate: formValue.date_picker_51oe0i,
        postalCode: formValue.text_input_agf1ki,
        email: formValue.text_input_4mdxvk,
        fax: formValue.text_input_2an17t,
        phone: formValue.text_input_bqewyt,
        address: formValue.text_input_aol9mx,
        unitIndustryTypeCode: formValue.single_select_197css,
        verticalManageStateCode: formValue.single_select_9l2zcc,
        verticalManageLevelCode: formValue.single_select_9fx606,
        verticalManageUnit: formValue.tree_single_select_85775k,
        unitStaffSize: formValue.number_input_86qfhb,
        settingBasis: formValue.textarea_dzpnbg
    };

    // 各种类型信息结构体
    const typeHandlers = {
        "1": { target: "superviseUnitInfoList", getData: () => ({
                id,
                unitPropertyCode: formValue.single_select_6h4dtp,
                superviseUnitId: formValue.tree_single_select_eyvn62
            })},
        "2": { target: "superviseUnitInfoList", getData: () => ({
                id,
                unitPropertyCode: formValue.single_select_775354,
                superviseUnitId: formValue.tree_single_select_eyvn62
            })},
        "3": { target: "superviseUnitInfoList", getData: () => ({
                id,
                unitPropertyCode: formValue.single_select_6h4dtp,
                superviseUnitId: formValue.tree_single_select_eyvn62
            })},
        "4": { target: "superviseUnitInfoList", getData: () => ({
                id,
                unitPropertyCode: formValue.single_select_775354,
                superviseUnitId: formValue.tree_single_select_eyvn62
            })},
        "5": { target: "subjectUnitInfoList", getData: () => ({
                id,
                unitPropertyCode: formValue.single_select_gl6qfp
            })},
        "6": { target: "subjectUnitInfoList", getData: () => ({
                id,
                subjectCategoryCode: formValue.single_select_4xhdme,
                lawSubjectId: formValue.tree_single_select_a7pozd
            })},
        "7": { target: "subjectUnitInfoList", getData: () => ({
                id,
                lawSubjectId: formValue.tree_single_select_a7pozd
            })},
        "8": { target: "delegationUnitInfoList", getData: () => {
                const table = formEle.$$getFormValue()["detail_table_hl9v69"] || [];
                return table
                    .filter(row => row.single_select_hoilag)
                    .map(row => ({
                        stdSubjectId: row.single_select_hoilag,
                        delegateModeType: row.single_select_f31blu,
                        delegateSettingBasis: row.text_input_mu7fk,
                        delegateStartDate: row.date_picker_51n8ah,
                        delegateEndDate: row.date_picker_9qltsk,
                        delegatePublicFlag: row.single_select_d7hy0z
                    }));
            }}
    };

    // 最终构建数据对象
    const result = {
        unitBaseInfo,
        superviseUnitInfoList: [],
        subjectUnitInfoList: [],
        delegationUnitInfoList: [],
        unitRelBizUnitInfoList: []
    };

    // 根据勾选的机构类型收集信息
    [...new Set(unitTypeCode)].forEach(code => {
        const handler = typeHandlers[code];
        if (handler) {
            const data = handler.getData();
            if (Array.isArray(data)) {
                result[handler.target].push(...data);
            } else if (data) {
                result[handler.target].push(data);
            }
        }
    });

    return result;
}
